package com.wuji1626.spark.rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object RDD_Transform_cogroup2 {

  def main(args: Array[String]): Unit = {
    // Step1: 准备环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    // Step2: 算子 cogroup
    val rdd1 = sc.makeRDD(List(("a",1),("b",2)))
    val rdd2 = sc.makeRDD(List(("b", 5), ("a", 6),("c",4),("c",3)))

    val cgRDD:RDD[(String,(Iterable[Int],Iterable[Int]))] = rdd1.cogroup(rdd2)
    cgRDD.collect().foreach(println)
    // Step3: 关闭环境
    sc.stop()
  }
}
